package com.cookie.utils;
import org.apache.ibatis.io.Resources;

import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;


/**
 * @author dyx
 * @description
 * @date 2024/12/25 16:41
 **/
public class MyBatisConfig {
    /**
     * 这部分经常重复使用，将其集中在这里
     * @return 返回一个SqlSessionFactory类型，以供调用
     */
    public static SqlSessionFactory CreateSqlSessionFactory() {
        String resource = "mybatis-config.xml";
        InputStream inputStream = null;
        try {
            inputStream = Resources.getResourceAsStream(resource);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return new SqlSessionFactoryBuilder().build(inputStream);

//        try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
//
//            NoteMapper noteMapper = sqlSession.getMapper(NoteMapper.class);
//
//            noteMapper.insertNote("note004", "周会记录", "good", "dyx", "工作");
//            sqlSession.commit();
//
//            List<Note> noteList = noteMapper.selectAll();
//
//            System.out.println(noteList);
//        }
    }
}
